'use strict';

const Controller = require('egg').Controller;

class QMTradeController extends Controller {

  async login(){
    const { ctx , app } = this
    let req = app.qmt.Request.login()
    app.qmt.write( req )

    ctx.body = 'ok'
  }

  async getAccountDetail(){
    const { ctx , app } = this

    let req = app.qmt.Request.reqAllAccountDetail()

    app.qmt.write( req )

    ctx.body = "Call reqAllAccountDetail success."
  }

  async buy() {
    const { ctx } = this;

    let msg = {}

    msg['header'] = {
      api : 'order'
    }

    msg['body'] = {
      moduleTag : 'order' ,
      nRequestId : 1000 ,
      m_dPrice : 6.47 ,
      m_nOrderNum : 300 ,
      m_strExchangeID : '600015' ,
      m_strInstrumentID : '' ,
      m_eOperationType : 'XTFW_OPT_FIN_BUY' ,
      m_ePriceType : 'XTFW_PRTP_LATEST' ,
      m_strRemark : '买入测试 600015'
    }

    this.app.qmt.write( msg )

    ctx.body = 'hi, man,' + this.app.test;
  }

}

module.exports = QMTradeController;
